package com.wqtz.chechai.widget;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * 项目名称： CheChai
 * 创建人 : Liberation
 * 创建时间: 2017/1/11 16:37
 * 设置recyclerview的间距
 */

public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
	private int space;

	public SpacesItemDecoration(int space) {
		this.space = space;
	}

	@Override
	public void getItemOffsets(Rect outRect, View view,
	                           RecyclerView parent, RecyclerView.State state) {
		outRect.left = space;
		outRect.right = space;
		outRect.bottom = space;

		// Add top margin only for the first item to avoid double space between items
		if (parent.getChildPosition(view) == 0)
			outRect.top = space;
	}
}
